package com.atguigu.eduservice.controller;


import com.atguigu.commonutils.ResultVo;
import com.atguigu.eduservice.entity.subject.OneSubject;
import com.atguigu.eduservice.service.EduSubjectService;
import com.atguigu.eduservice.service.EduTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2024-12-09
 */
@RestController
@Api(tags="课程分类管理")
@RequestMapping("/eduservice/subject")
@CrossOrigin
public class EduSubjectController {

    @Autowired
    private EduSubjectService eduSubjectService;

    //添加课程分类
    //获取上传过来的文件，把内容读取出来，就不用上传到服务器
    @ApiOperation(value = "Excel批量导入")
    @PostMapping("addSubject")
    public ResultVo addSubject(MultipartFile file){
        // 获取上传的excel文件 MultipartFile
        eduSubjectService.saveSubject(file,eduSubjectService);

        return ResultVo.ok();
    }
    @ApiOperation(value = "嵌套数据列表")
    @GetMapping("/getAllSubject")
    //课程分类列表(树形)
    public ResultVo getAllSubject(){
        //list集合泛型是一级分类，因为一级分类有他本身和二级分类的集合
        List<OneSubject> list= eduSubjectService.getAllOneTwoSubject();
        return ResultVo.ok().data("list",list);
    }


}
